<!--
//******************************************************************
//* Copyright (c) 2008 Ford Motor Company. All Rights Reserved.
//*
//*
//* $$Workfile:   paymentPolicyDefinition.jsp  $$
//* $$Revision:   1.2  $$
//* $$Author:   TMALDON4  $$
//* $$Date:   Dec 19 2008 08:48:56  $$
//*
//* Description: Description of file goes here
//******************************************************************
-->
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="display-el" %>
<%@ taglib uri="ford-arg/tags" prefix="ft" %>

<script language="JavaScript" src="./scripts/CalendarPopup.js"></script>
<script language="JavaScript" src="./scripts/popups.js"></script>
<script type="text/javascript" language="javascript" src="./scripts/ajaxSearch.js"></script>
<script language="javascript">		
	var cal = new CalendarPopup(); 
	cal.showNavigationDropdowns();
	cal.setMonthNames('<bean:message key="label.month.january"/>',
						'<bean:message key="label.month.february"/>',
						'<bean:message key="label.month.march"/>',
						'<bean:message key="label.month.april"/>',
						'<bean:message key="label.month.may"/>',
						'<bean:message key="label.month.june"/>',
						'<bean:message key="label.month.july"/>',
						'<bean:message key="label.month.august"/>',
						'<bean:message key="label.month.september"/>',
						'<bean:message key="label.month.october"/>',
						'<bean:message key="label.month.november"/>',
						'<bean:message key="label.month.december"/>');
	cal.setDayHeaders('<bean:message key="label.day.sunday.capital"/>',
						'<bean:message key="label.day.monday.capital"/>',
						'<bean:message key="label.day.tuesday.capital"/>',
						'<bean:message key="label.day.wednesday.capital"/>',
						'<bean:message key="label.day.thursday.capital"/>',
						'<bean:message key="label.day.friday.capital"/>',
						'<bean:message key="label.day.saturday.capital"/>');
	cal.setTodayText('<bean:message key="label.today"/>');

	function lookupSupplier() {
		searchNameSupplier("lookupedSupplier", "supplierCode", "supplierClass");
	}

	function save() {
		document.PaymentPolicyDefinitionForm.action = "PaymentPolicyDefinitionActionSave.do";
		document.PaymentPolicyDefinitionForm.section.value = "save";
		document.PaymentPolicyDefinitionForm.submit();	
	}
	
	function backToFullEconomic(){
		document.PaymentPolicyDefinitionForm.action = "PaymentPolicyDefinitionActionBackToFullE.do";
		document.PaymentPolicyDefinitionForm.section.value = "backToFullE";
		document.PaymentPolicyDefinitionForm.submit();	
	}

	function propose() {
		document.PaymentPolicyDefinitionForm.action = "PaymentPolicyDefinitionActionPropose.do";
		document.PaymentPolicyDefinitionForm.section.value = "propose";
		document.PaymentPolicyDefinitionForm.submit();
	}

	function approve() {
		document.PaymentPolicyDefinitionForm.action = "PaymentPolicyDefinitionActionApprove.do";
		document.PaymentPolicyDefinitionForm.section.value = "approve";
		document.PaymentPolicyDefinitionForm.submit();
	}
	
	function cancel(){
		document.PaymentPolicyDefinitionForm.action = "PaymentPolicyActionInit.do";
		document.PaymentPolicyDefinitionForm.section.value = "cancel";
		document.PaymentPolicyDefinitionForm.submit();	
	}
	
	function findItems( options ) {
		if(document.getElementById('itemRadio').checked){
			var req = null;
			var itemCategory = options[options.selectedIndex].value;
			
			if (window.XMLHttpRequest) {
				req = new XMLHttpRequest();
			} else if (window.ActiveXObject) {
				try {
					req = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
						req = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {
					}
				}
			}
			req.onreadystatechange = function( ) {
				if (req.readyState == 4) {
					document.getElementById("item").innerHTML = req.responseText;
					document.getElementById("itemCb").options[0].text = '<bean:message key="label.selectOption" />'
				}
			};
			req.open("GET", "PaymentPolicyDefinitionActionFindItems.do?itemCategory="+itemCategory+"&r="+Math.random(), true);
			req.setRequestHeader("Content-Type",
					"application/x-www-form-urlencoded");
			req.send(null);
		}
	}
	
	
	function enableDiv(id, status, clear) {
		var hijos = document.getElementById(id).childNodes;
		for (var i = 0; i < hijos.length; i++) {
			if (hijos[i].tagName=="SELECT" || hijos[i].tagName=="INPUT") {
				hijos[i].disabled = !status;
				if(clear){
					if (hijos[i].tagName=="SELECT") {
						hijos[i].selectedIndex = 0;
					} else if (hijos[i].tagName=="INPUT" && hijos[i].type=="text") {
						hijos[i].value="";
					}
				}
			}
		};		
	}
	
	function enableItem(){
		
		enableDiv('item',true,true);
		findItems(document.getElementById('itemCategory'))
	}
	
	function disableItem(){
		enableDiv('item',false,true);
		document.getElementById("itemCb").options[0].text = '<bean:message key="label.allOption" />';
	}


</script>

<table>
	<tr>
		<td><h2><bean:message key="paymentPolicyDefinition.label.title"/></h2></td>
	</tr>
</table>
<br/>
<logic:equal name="PaymentPolicyDefinitionForm" property="operation" value="newPayPol">
	<bean:define id="disable">false</bean:define>
</logic:equal>
<logic:notEqual name="PaymentPolicyDefinitionForm" property="operation" value="newPayPol">
	<bean:define id="disable">true</bean:define>
</logic:notEqual>
<logic:empty name="PaymentPolicyDefinitionForm" property="payPolVersSelected.eese05PpyverProposalUserC">
	<bean:define id="disableVersion">false</bean:define>
</logic:empty>
<logic:notEmpty name="PaymentPolicyDefinitionForm" property="payPolVersSelected.eese05PpyverProposalUserC">
	<bean:define id="disableVersion">true</bean:define>
</logic:notEmpty>
<html:form action="/PaymentPolicyDefinitionActionNew">
<html:hidden property="section" />
	<table style="width: 800px;" class="no_border">
		<tr>
			<td  class="text_blue_bold align_left" colspan="100%">
				<bean:message key="paymentPolicyDefinition.label.id" />:
				<logic:equal name="PaymentPolicyDefinitionForm" property="operation" value="newPayPol"><bean:message key="costStructure.new.label.auto" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</logic:equal>
				<logic:notEqual name="PaymentPolicyDefinitionForm" property="operation" value="newPayPol"><bean:write name="PaymentPolicyDefinitionForm" property="payPolVersSelected.teese04Paypolicy.eese04PaypolNumberK" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</logic:notEqual>
				<bean:message key="paymentPolicyDefinition.label.version" />:
				<logic:equal name="PaymentPolicyDefinitionForm" property="operation" value="newVersion"><bean:message key="costStructure.new.label.auto" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</logic:equal>
				<logic:notEqual name="PaymentPolicyDefinitionForm" property="operation" value="newVersion"><bean:write name="PaymentPolicyDefinitionForm" property="payPolVersSelected.eese05PpyverVersionNumberK" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</logic:notEqual>
				<b><bean:message key="paymentPolicyDefinition.label.status" />: <bean:message key="label.draft" /></b>
			</td>
		</tr>
		<tr height="10px"></tr>
		<tr>
			<td class="text_blue_bold align_left" style="width: 12%" colspan="2">
				<bean:message key="paymentPolicyDefinition.label.supplier" />&nbsp;&nbsp;&nbsp;&nbsp;
			</td>
			<td class="align_left" style="width: 88%" colspan="4">
				<div id="supplierDiv">
				<html:select property="supplierClass" disabled="${disable}" styleId="supplierClass">
					<html:option value="-1"><bean:message key="label.selectOption" /></html:option>				
					<html:options collection="partClassColl" property="value" labelProperty="label"/>
				</html:select>
				&minus;
				<html:text property="supplierCode" styleId="supplierCode" maxlength="6" size="6" disabled="${disable}"/>
				<html:button property="lookupSupp" onclick="lookupSupplier();" styleClass="button_small" disabled="${disable}">...</html:button>
				<html:button property="findSupp" onclick="findSupplierPopup('supplierClass','supplierCode');" styleClass="button_small" style="width:20px;" disabled="${disable}">?</html:button>		
				<div style="display:inline;" id="lookupedSupplier" />
				</div>
			</td>
		</tr>
		<tr height="10px"/>
		<tr>
			<td class="text_blue_bold align_left" >
				<html:radio property="itemScope" styleId="categoryRadio" value="C" onclick="disableItem();" disabled="${disable}"></html:radio>
			</td>
			<td class="text_blue_bold align_left">
				<bean:message key="costStructure.itemCategory" />
			</td>
			<td class="text_blue_bold align_left" colspan="4">
				<div id="itemCat">			
				<html:select property="itemCategory" styleId="itemCategory" onchange="findItems(this)" disabled="${disable}">
					<html:option value="-1"><bean:message key="label.selectOption" /></html:option>
					<html:options collection="ItemCategoryColl"
								  property="eesc05ItemcatgryNumberK"
								  labelProperty="eesc05ItemcatgryNameN" />
				</html:select>
				</div>
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<html:radio property="itemScope" styleId="itemRadio" value="I" onclick="enableItem()" disabled="${disable}"></html:radio>
			</td>
			<td class="text_blue_bold align_left">	
				<bean:message key="costStructure.item" />&nbsp;&nbsp;&nbsp;
			</td>
			<td class="text_blue_bold align_left" colspan="4">	
				<div id="item">
				<html:select property="item" styleId="itemCb" disabled="${disable}">
					<html:option value="-1"><bean:message key="label.selectOption" /></html:option>
					<html:options collection="ItemColl"
								  property="eesc06ItemNumberK"
								  labelProperty="eesc06ItemNameN" />
				</html:select>
				</div>	
			</td>
		</tr>
		<tr height="10px"/>
		<tr>
			<td class="align_left" colspan="3" style="width: 38%">
				<table>
					<tr>
						<td class="text_blue_bold align_left" colspan="2" width="50%">
							<bean:message key="paymentPolicyDefinition.label.dateIn" />
						</td>
						<td class="text_blue_bold align_left" width="50%">
							<html:text property="dateIn" styleId="dateIn" maxlength="10" size="10" disabled="${disableVersion}"/><A name="dateInAnchor"> </A><html:button property="calendarIn" onclick="cal.select(document.PaymentPolicyDefinitionForm.dateIn,'dateInAnchor','dd/MM/yyyy'); return false;" styleClass="button_small" disabled="${disableVersion}">...</html:button>
						</td>
					</tr>
					<tr>
						<td class="text_blue_bold align_left" colspan="2">
							<bean:message key="paymentPolicyDefinition.label.dateOut" />
						</td>
						<td class="text_blue_bold align_left">
							<html:text property="dateOut"  styleId="dateOut" maxlength="10" size="10" disabled="${disableVersion}"/><A name="dateOutAnchor"> </A><html:button property="calendarOut" onclick="cal.select(document.PaymentPolicyDefinitionForm.dateOut,'dateOutAnchor','dd/MM/yyyy'); return false;" styleClass="button_small" disabled="${disableVersion}">...</html:button>				
						</td>
					</tr>
					<tr height="10px"/>
					<tr>
						<td class="text_blue_bold align_left" width="35%">
							<bean:message key="paymentPolicyDefinition.label.value" />&nbsp;&nbsp;&nbsp;&nbsp;
						</td>
						<td class="text_blue_bold align_left" colspan="2" width="65%">
							<html:text property="value"  styleId="value" maxlength="10" size="10" disabled="${disableVersion}"/>
						</td>
					</tr>
				</table>
			</td>
			<td style="width: 35%" class="align_left">
			<logic:notEmpty name="PaymentPolicyDefinitionForm" property="prevPayPolVers">
				<table class="outlined">
					<tr class="no_border">
						<td >
							<h3 style="text-decoration: underline;"><bean:message key="paymentPolicyDefinition.label.priorVersion" /></h3>
						</td>
					</tr>
					<tr>
						<td class="text_blue_bold align_left" colspan="2">
							<bean:message key="paymentPolicyDefinition.label.dateIn" />:&nbsp;
							<bean:write name="PaymentPolicyDefinitionForm"  property="prevDateIn"/>
						</td>
					</tr>
					<tr>
						<td class="text_blue_bold align_left" colspan="2">
							<bean:message key="paymentPolicyDefinition.label.dateOut" />:&nbsp;
							<bean:write name="PaymentPolicyDefinitionForm" property="prevDateOut"/>
						</td>
					</tr>
					<tr height="10px"/>
					<tr>
						<td class="text_blue_bold align_left">
							<bean:message key="paymentPolicyDefinition.label.value" />&nbsp;=&nbsp;
							<bean:write name="PaymentPolicyDefinitionForm" property="prevValue"/>%						
						</td>
					</tr>
				</table>
			</logic:notEmpty>
			</td>
			<td style="width: 27%"/>
		</tr>
		<tr>
			<td class="text_blue_bold align_left" colspan="100%">
				<bean:message key="paymentPolicyDefinition.label.obs" />
			</td>
		</tr>
		<tr>
			<td class="align_left" colspan="100%">
				<html:textarea property="observations" rows="3" style="width:800px;" disabled="${disableVersion}"/>
			</td>
		</tr>
	</table>
	<br />
	<br />
	<table style="width: 800px;">
		<tr>
			<td class="align_left">		
			<logic:equal name="PaymentPolicyDefinitionForm" property="operation" value="editVersion">	
				<table align="left" class="table1" style="width: 400px;">
					<tr>
						<td class="align_left">									
							<logic:notEmpty property="payPolVersSelected.eese05CreateUserC" name="PaymentPolicyDefinitionForm">
								<bean:define id="createdBy" name="PaymentPolicyDefinitionForm" property="payPolVersSelected.eese05CreateUserC" />
								<bean:define id="createdDate" name="PaymentPolicyDefinitionForm" property="createdDate" />
								<bean:message key="text.createdBy" arg0="${createdBy}" arg1="${createdDate}" />
							</logic:notEmpty>
						</td>
					</tr>
					<tr>
						<td class="align_left">
							<logic:notEmpty property="payPolVersSelected.eese05CreateUserC" name="PaymentPolicyDefinitionForm">
								<logic:empty property="payPolVersSelected.eese05PpyverProposalUserC" name="PaymentPolicyDefinitionForm">
									<html:button property="prop" onclick="propose();" styleClass="button_small"><bean:message key="label.propose" /></html:button>
								</logic:empty>
							</logic:notEmpty>
							<logic:notEmpty property="payPolVersSelected.eese05PpyverProposalUserC" name="PaymentPolicyDefinitionForm">
								<bean:define id="proposedBy" name="PaymentPolicyDefinitionForm" property="payPolVersSelected.eese05PpyverProposalUserC" />
								<bean:define id="proposedDate" name="PaymentPolicyDefinitionForm" property="proposedDate" />
								<bean:message key="text.proposedBy" arg0="${proposedBy}" arg1="${proposedDate}" />
							</logic:notEmpty>
						</td>								
					</tr>
					<tr>
						<td class="align_left">
							<logic:notEmpty property="payPolVersSelected.eese05PpyverProposalUserC" name="PaymentPolicyDefinitionForm">
								<logic:empty property="payPolVersSelected.eese05PpyverApprovalUserC" name="PaymentPolicyDefinitionForm">
									<html:button property="appr" onclick="approve();" styleClass="button_small"><bean:message key="label.approve" /></html:button>											
								</logic:empty>											
							</logic:notEmpty>
							<logic:notEmpty property="payPolVersSelected.eese05PpyverApprovalUserC" name="PaymentPolicyDefinitionForm">
								<bean:define id="approvedBy" name="PaymentPolicyDefinitionForm" property="payPolVersSelected.eese05PpyverApprovalUserC" />
								<bean:define id="approvedDate" name="PaymentPolicyDefinitionForm" property="approvedDate" />
								<bean:message key="text.approvedBy" arg0="${approvedBy}" arg1="${approvedDate}" />
							</logic:notEmpty>
						</td>
					</tr>
					<tr>
						<td class="align_left">
							<logic:notEmpty property="payPolVersSelected.eese05LastUpdtUserC" name="PaymentPolicyDefinitionForm">
								<bean:define id="lastModifiedBy" name="PaymentPolicyDefinitionForm" property="payPolVersSelected.eese05LastUpdtUserC" />
								<bean:define id="lastModifiedDate" name="PaymentPolicyDefinitionForm" property="lastModifiedDate" />										
								<bean:message key="text.lastModifiedBy" arg0="${lastModifiedBy}" arg1="${lastModifiedDate}" />											
							</logic:notEmpty>
						</td>
					</tr>
				</table>
				</logic:equal>
			</td>
			<td class="align_right">
				<html:button property="savePayPol" onclick="save();" styleClass="button" disabled="${disableVersion}"><bean:message key="label.save" /></html:button>
				<logic:equal name="PaymentPolicyDefinitionForm" property="operation" value="editVersion">
					<logic:notEmpty name="PaymentPolicyDefinitionForm" property="fullEconomic">
						&nbsp;<html:button property="backToFullE" onclick="backToFullEconomic();" styleClass="button"><bean:message key="paymentPolicyDefinition.label.backToFullEconomics" /></html:button>
					</logic:notEmpty>
				</logic:equal>
			</td>
			<td class="align_right"  style="width: 75px;">			
				<input type="button" value="<bean:message key='label.cancel'/>" class="button" onclick="cancel()" />
			</td>
		</tr>		
	</table>
</html:form>
<script language="javascript">
		if(document.getElementById("itemScope").value == "I")
				alert(document.getElementById("itemScope").value)
			enableItem();
		if(document.getElementById("itemScope").value == "C"){
			disableItem();
		}
</script>